package arcane.object.game.engine;

import java.awt.Dimension;

import arcane.constant.Constants;
import arcane.object.game.sprite.MenuSprite;
import arcane.object.screen.MultiplayerLoginScreen;
import arcane.object.screen.MultiplayerLoungeScreen;
import arcane.object.screen.PlayScreen;
import arcane.object.screen.TitleScreen;

import com.golden.gamedev.GameEngine;
import com.golden.gamedev.GameObject;
import com.golden.gamedev.OpenGLGameLoader;
/**
 * The Arcane Game Engine.  This is the application entry point.  Used mainly to formalize
 * the relationship between screens, and in screen management.
 * @author William Morrison
 *
 */
public class ArcaneEngine extends GameEngine {
	/**
	 * Flag for engine to call MenuScreen
	 */
	public static final int MENU_SCREEN = 0;

	/**
	 * Flag for engine to call PlayScreen
	 */
	public static final int PLAY_SCREEN = 1;

	/**
	 * Flag for engine to call Multi player Screen
	 */
	public static final int MULTI_SCREEN = 2;
	
	/**
	 * Flag for engine to call Multiplayer Lounge Screen
	 */
	public static final int MULTI_LONGE=3;

	/**
	 * PlayScreen object, where all main game logic occurs
	 */
	PlayScreen playScreen;

	/**
	 * MenuScreen object, first screen called. The start menu essentially.
	 */
	TitleScreen menuScreen;

	/**
	 * MultiplayerScreen object, called for multiplayer support...
	 */
	MultiplayerLoginScreen multiplayerScreen;

	/**
	 * Where players wait prior to joining a game. Displays lists of games, and
	 * chat channel to communicate with other players trying to find games to
	 * join.
	 */
	MultiplayerLoungeScreen multiplayerLonge;

	public ArcaneEngine() {
		super();
	}

	/**
	 * Initializes all screens and global resources.
	 */
	public void initResources() {
		Constants.keyStroke = this.bsInput;
		MenuSprite.bsInput = bsInput;
		
		playScreen = new PlayScreen(this);
		menuScreen = new TitleScreen(this);
		multiplayerScreen = new MultiplayerLoginScreen(this);
		multiplayerLonge = new MultiplayerLoungeScreen(this);

		this.nextGameID = MULTI_SCREEN;
	}

	/**
	 * Returns the appropriate game object based on user defined logic.
	 * Implemented "behind-the-scenes" by GTGE.
	 */
	public GameObject getGame(int id) {
		switch (id) {
		case PLAY_SCREEN:
			return playScreen;
		case MENU_SCREEN:
			return menuScreen;
		case MULTI_SCREEN:
			return multiplayerScreen;
		case MULTI_LONGE:
			multiplayerLonge.setClient(multiplayerScreen.client);
			return multiplayerLonge;
		default:
			return null;
		}
	}

	/**
	 * Main method. Initializes game canvas, and LWJGL rendering acceleration.
	 * 
	 * @param args
	 *            no uses.
	 */
	public static void main(String[] args) {
		OpenGLGameLoader game = new ArcaneGameLoader();
		// GameLoader game = new GameLoader();
		ArcaneEngine engine = new ArcaneEngine();
		//engine.distribute = true;
		game.setupLWJGL(engine, new Dimension(640, 480), false);
		// game.setup(engine, new Dimension(640, 480), false);
		game.start();
	}
}